-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of v0 mangling #2615
Conversation
389952a
to
b5c7f2b
Compare
deleted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great starting point to me - I assume you've compared the output strings with rustc?
gcc/rust/backend/rust-mangle.cc
Outdated
rust_unreachable (); | ||
std::string mangled; | ||
|
||
path.iterate_segs ([&] (const Resolver::CanonicalPath &seg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this lambda is very long and would benefit from being split up in multiple tinier functions - but this can be addressed later before the PR gets merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed in this PR.
gcc/rust/backend/rust-mangle.cc
Outdated
case HIR::ImplItem::FUNCTION: { | ||
prefix = "N"; | ||
ns = "v"; | ||
HIR::Function *fn = static_cast<HIR::Function *> (impl_item); | ||
if (!fn->get_generic_params ().empty ()) | ||
{ | ||
generic_prefix = "I"; | ||
generic_postfix = v0_generic_arg (ty) + "E"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example here you could factor this into a function, which would take an HIR::Function&
as argument and do the required handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Partially yes, but mangled symbols contain metadata so I checked by demangling mangled symbols with rustc_demangle. Here is a wrapper of rustc_demangle I am I using this |
401362e
to
c53ebc2
Compare
280285b
to
b5b600c
Compare
#include "rust-common.h" | ||
#include "rust-hir-expr.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lacking include
This rz-libdemangle library might be helpful for you too, we support Rust demangling implemented in pure C. |
@CohenArthur |
gcc/rust/ChangeLog: * backend/rust-compile-context.h: Modify declaration. * backend/rust-mangle.cc (struct V0Path): New struct. (v0_path): New function. (legacy_mangle_name): Take Context as argument. (v0_numeric_prefix): Fix type strings. (v0_complex_type_prefix): New function. (v0_add_integer_62): Deleted (v0_integer_62): New function. (v0_add_opt_integer_62): Deleted. (v0_opt_integer_62): New function. (v0_add_disambiguator): Deleted. (v0_disambiguator): New function. (v0_type_prefix): Support more types. (v0_generic_args): New function. (v0_add_identifier): Deleted. (v0_identifier): New function. (v0_type_path): New function. (v0_function_path): New function. (v0_scope_path): New function. (v0_crate_path): New function. (v0_inherent_or_trait_impl_path): New function. (v0_mangle_item): Use v0_path. (Mangler::mangle_item): Take Context as argument. * backend/rust-mangle.h (class Context): Add forward declaration. * hir/tree/rust-hir-item.h: Fix include. Signed-off-by: Raiki Tamura <[email protected]>
@tamaroning thanks for the ping :) merging now |
Addresses #2635
Depends on #2633
Implemented mangling of basic paths.
Traits and generic ADTs cannot be mangled yet
I will add tests later.
Example
changelog